package com.wangzemin.leetcoded.num518;

public class Solution {
    public int change(int amount, int[] coins) {
        int[][] dp = new int[amount + 1][coins.length + 1];
        for (int i = 0; i <= amount; i++) {
            dp[i][0] = 0;
        }
        for (int i = 0; i <= coins.length; i++) {
            dp[0][i] = 1;
        }
        for (int i = 1; i <= amount; i++) {
            for (int j = 1; j <= coins.length; j++) {
                if (i < coins[j - 1]) {
                    dp[i][j] = dp[i][j - 1];
                } else {
                    dp[i][j] = dp[i][j - 1] + dp[i - coins[j - 1]][j];
                }
            }
        }
        return dp[amount][coins.length];
    }

//    public static void main(String[] args) {
//        Solution solution = new Solution();
//        System.out.println(solution.change(5, new int[]{1, 2, 5}));
//        System.out.println(solution.change(3, new int[]{2}));
//        System.out.println(solution.change(3, new int[]{3}));
//
//    }
}